package com.yidian.service.impl;

import com.yidian.entity.Channel;
import com.yidian.entity.ChannelUsersKey;
import com.yidian.mapper.ChannelMapper;
import com.yidian.mapper.ChannelUsersMapper;
import com.yidian.service.ChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("channelService")
public class ChannelServiceImpl implements ChannelService {

    @Autowired
    private ChannelMapper channelMapper;
    @Autowired
    private ChannelUsersMapper channelUsersMapper;

    /**
     * 获取所有频道
     *
     * @return
     */
    @Override
    public List<Channel> getAllChannel() {
        return channelMapper.selectByExample(null);
    }

    /**
     * 添加用户频道
     *
     * @param channelUsersKey
     */
    @Override
    public void addUserChannel(ChannelUsersKey channelUsersKey) {
        channelUsersMapper.insertSelective(channelUsersKey);
    }

    /**
     * 删除用户频道
     *
     * @param channelUsersKey
     */
    @Override
    public void deleteUserChannel(ChannelUsersKey channelUsersKey) {
        channelUsersMapper.deleteByPrimaryKey(channelUsersKey);
    }

    @Override
    public List<Channel> selectChannelByUserId(long id) {
        return channelMapper.selectChannelByUserId(id);
    }
}
